//
//  MYGHealthMenuCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/4.
//

import UIKit

class MYGHealthMenuCell: UITableViewCell {
    // MARK: - Property
    var model: MYGHealthMenuCellModel? {
        didSet {
            guard let model = model else {
                return
            }
            
            nameLabel.text = model.name
            contentLabel.text = model.content
            selectButton.isSelected = model.isSel
            selectButton.layer.borderWidth = model.isSel ? 0 : 1
        }
    }
    
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - UI
    private func configUI() {
        contentView.addSubview(selectButton)
        contentView.addSubview(stackView)
        
        stackView.addArrangedSubviews([nameLabel, contentLabel])
        
        selectButton.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(28)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(15)
        }
        
        stackView.snp.makeConstraints { make in
            make.left.equalTo(selectButton.snp.right).offset(14)
            make.right.equalToSuperview().inset(10)
            make.centerY.equalToSuperview()
        }
        
        selectButton.setContentHuggingPriority(.required, for: .horizontal)
        selectButton.setContentCompressionResistancePriority(.required, for: .horizontal)
    }
    
    // MARK: - lazy load
    private lazy var selectButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "Chat/Menu/circle_sel"), for: .selected)
        btn.setImage(UIImage(named: "Chat/Menu/circle"), for: .normal)
        btn.isUserInteractionEnabled = false
        btn.backgroundColor = .white
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 7.5
        btn.layer.borderWidth = 1
        btn.layer.borderColor = UIColor.rgba(174, 174, 174, 1).cgColor
        return btn
    }()
    
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .vertical
        stackV.spacing = 5
        return stackV
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(15)
        label.textColor = .rgba(44, 44, 44, 1)
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(13)
        label.textColor = .rgba(128, 128, 128, 1)
        return label
    }()
}
